﻿<%@ WebHandler Language="C#" Class="ListProduct" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.Collections.Generic;

using FiveSister.BAL;

public class ListProduct : AdminHandler
{

    public override void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        if (IsAuthenticate(context))
        {
            try
            {
                int pageIndex = 1, pageMax = 10, groupProduct = 1, brandId = 1;

                if (context.Request.QueryString["pi"] != null)
                    pageIndex = int.Parse(context.Request.QueryString["pi"].ToString());
                if (context.Request.QueryString["pm"] != null)
                    pageMax = int.Parse(context.Request.QueryString["pm"].ToString());
                if (context.Request.QueryString["gi"] != null)
                    groupProduct = int.Parse(context.Request.QueryString["gi"].ToString());
                if (context.Request.QueryString["bi"] != null)
                    brandId = int.Parse(context.Request.QueryString["bi"].ToString());
                ///Lỗi procedure
                if (pageIndex == 0)
                    pageIndex = 1;

                string result = "";
                Product obj = new Product();
                IList<Product> list = obj.List(pageIndex, pageMax, groupProduct, brandId);
                result = obj.ToJsonList<Product>(list);
                context.Response.Write(result);
            }
            catch (Exception ex)
            {
                PMSA.Framework.Log.CLogManager.Write("ListProduct.ashx", ex.ToString(), "ADMIN");
                context.Response.Write("FAIL");
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}